package com.ruoyi.internship.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.internship.dto.PositionApplicationDTO;
import com.ruoyi.internship.service.IPositionApplicationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.internship.domain.BolePostionApplication;
import com.ruoyi.internship.service.IBolePostionApplicationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 职位申请记录Controller
 * 
 * @author Wujiale
 * @date 2025-03-29
 */
@RestController
@RequestMapping("/internship/application")
public class BolePostionApplicationController extends BaseController
{
    @Autowired
    private IBolePostionApplicationService bolePostionApplicationService;

    @Autowired
    private IPositionApplicationService iPositionApplicationService;
    //通过审核时加上积分

//查看自己有无申请过
    @GetMapping("/isApplication")
    public AjaxResult isApplication(BolePostionApplication bolePostionApplication)
    {
        BolePostionApplication bolePostionApplication1 = bolePostionApplicationService.selectBolePostionApplicationByUserIdAndPositionId(bolePostionApplication);
        return success(bolePostionApplication1);
    }
    /**
     * 查询职位申请记录列表
     */
//    @PreAuthorize("@ss.hasPermi('internship:application:list')")
    @GetMapping("/list")
    public TableDataInfo list(BolePostionApplication bolePostionApplication)
    {
        startPage();
//        List<BolePostionApplication> list = bolePostionApplicationService.selectBolePostionApplicationList(bolePostionApplication);
        List<PositionApplicationDTO> list = iPositionApplicationService.selectBolePostionApplicationList(bolePostionApplication);
        return getDataTable(list);
    }

    /**
     * 导出职位申请记录列表
     */
    @PreAuthorize("@ss.hasPermi('internship:application:export')")
    @Log(title = "职位申请记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BolePostionApplication bolePostionApplication)
    {
        List<BolePostionApplication> list = bolePostionApplicationService.selectBolePostionApplicationList(bolePostionApplication);
        ExcelUtil<BolePostionApplication> util = new ExcelUtil<BolePostionApplication>(BolePostionApplication.class);
        util.exportExcel(response, list, "职位申请记录数据");
    }

    /**
     * 获取职位申请记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('internship:application:query')")
    @GetMapping(value = "/{applicationId}")
    public AjaxResult getInfo(@PathVariable("applicationId") String applicationId)
    {
        return success(bolePostionApplicationService.selectBolePostionApplicationByApplicationId(applicationId));
    }

    /**
     * 新增职位申请记录
     */
//    @PreAuthorize("@ss.hasPermi('internship:application:add')")
    @Log(title = "职位申请记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BolePostionApplication bolePostionApplication,Integer score)
    {

        System.out.println(score);
//        return toAjax(1);
        return toAjax(bolePostionApplicationService.insertBolePostionApplication(bolePostionApplication,score));
    }

    /**
     * 修改职位申请记录
     */
    @PreAuthorize("@ss.hasPermi('internship:application:edit')")
    @Log(title = "职位申请记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BolePostionApplication bolePostionApplication)
    {
        return toAjax(bolePostionApplicationService.updateBolePostionApplication(bolePostionApplication));
    }

    /**
     * 删除职位申请记录
     */
    @PreAuthorize("@ss.hasPermi('internship:application:remove')")
    @Log(title = "职位申请记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{applicationIds}")
    public AjaxResult remove(@PathVariable String[] applicationIds)
    {
        return toAjax(bolePostionApplicationService.deleteBolePostionApplicationByApplicationIds(applicationIds));
    }
}
